package com.spzx.product.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spzx.common.core.constant.ServiceNameConstants;
import com.spzx.common.core.domain.R;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.dto.OrderStockDTO;
import com.spzx.product.api.domain.query.ProductSkuQuery;
import com.spzx.product.api.domain.vo.ProductSkuVO;
import com.spzx.product.api.factory.RemoteProductFallbackFactory;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@FeignClient(contextId = "remoteProductService"
        ,value = ServiceNameConstants.PRODUCT_SERVICE //注册中心的服务名
        , fallbackFactory = RemoteProductFallbackFactory.class //降级工厂
)
public interface RemoteProductService {

    @Operation(summary = "内部调用接口：查询首页热门数据")
    @GetMapping("product/listIndexSkus")
    public R<List<ProductSku>> listIndexSkus();


//SpringQueryMap  openfegin 将对象转为请求参数的注解
    @Operation(summary = "内部调用接口：条件查询sku分页数据")
    @GetMapping("product/listSkus")
    public R<Page<ProductSku>> listSkus(@SpringQueryMap  ProductSkuQuery query);
    // ！！！记得加一级路径！！！/product/

    @Operation(summary = "内部调用接口：查询sku详情页数据")
    @GetMapping("product/getSkuDetails/{skuId}")
    public R<ProductSkuVO> getSkuDetails(@PathVariable("skuId") Long skuId );



    @Operation(summary = "内部调用接口：查询一组sku的价格")
    @GetMapping("product/getSkusPrice")
    public R<Map<Long, BigDecimal>> getSkusPrice(@RequestBody List<Long> skuIds );



    @Operation(summary = "内部调用接口：验库存锁库存")
    @PostMapping("stock/checkAndLockStock")
    public R<List<OrderStockDTO>> checkAndLockStock(@RequestBody List<OrderStockDTO> orderStockDTOS);
}
